package com.sxu.restfulapi;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("rest")
public class RestFulController {
    /**
     * Rest设计原则：
     *  1. 使用Rest的URL
     *  2. 使用四种请求方式
     *  3. 通常服务返回的格式是JSON、XML格式
     */

    @GetMapping("findOne/{id}/{name}")
    @ResponseBody
    public String findOne(@PathVariable("id") String id, @PathVariable("name") String name) {
        System.out.println("id:" + id);
        System.out.println("name:" + name);
        return "ok";
    }

    @PutMapping("save")
    @ResponseBody
    public String save(@RequestParam("id") String id, @RequestParam("name") String name) {
        System.out.println("id:" + id);
        System.out.println("name:" + name);
        return "ok";
    }

    @PostMapping("update")
    @ResponseBody
    public String update(@RequestParam("id") String id, @RequestParam("name") String name) {
        System.out.println("id:" + id);
        System.out.println("name:" + name);
        return "ok";
    }

    @DeleteMapping("delete/{id}")
    @ResponseBody
    public String delete(@RequestParam("id") String id) {
        System.out.println("id:" + id);
        return "ok";
    }
}
